package com.scoy.honeymei.activity.me;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.R;
import com.scoy.honeymei.activity.WebActivity;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.MeConstant;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.MyUtil;
import com.scoy.honeymei.utils.SPHelper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: SystemActivity$
 * @Description: 系统设置
 * @Author: GaoZhan
 * @CreateDate: 2019/9/11/0011$ 上午 10:17$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/11/0011$ 上午 10:17$
 * @UpdateRemark: 更新内容
 */
public class SystemActivity extends BaseActivity {

    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.title_tv)
    TextView titleTv;
    @BindView(R.id.sign_tv)
    TextView signTv;
    @BindView(R.id.title_llt)
    LinearLayout titleLlt;
    @BindView(R.id.sys_aboutus_tv)
    TextView sysAboutusTv;
    @BindView(R.id.sys_version_tv)
    TextView sysVersionTv;
    @BindView(R.id.sys_out_tv)
    TextView sysOutTv;
    @BindView(R.id.sys_yinsi_tv)
    TextView sysYinsiTv;
    @BindView(R.id.sys_delete_tv)
    TextView sysDeleteTv;
    private SystemActivity mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system);
        ButterKnife.bind(this);
        mContext = SystemActivity.this;

        initNormal();
    }

    @Override
    public void initNormal() {
        titleTv.setText(R.string.systemset);
        MyUtil.setStatusBar(mContext, getWindow(), true, R.color.colorWhite);
        titleLlt.setPadding(0, MyUtil.getStatusBarHeight(mContext), 0, 0);

        sysVersionTv.setText(MyUtil.getVerName(mContext));

    }

    @OnClick({R.id.back_iv, R.id.sys_aboutus_tv, R.id.sys_out_tv, R.id.sys_yinsi_tv, R.id.sys_delete_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.sys_aboutus_tv:
                Intent intent = new Intent(mContext, WebActivity.class);
                intent.putExtra("webType", 1);
                startActivity(intent);
                break;
            case R.id.sys_out_tv:
                new AlertDialog.Builder(mContext).setTitle("确认退出登录？").setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).setPositiveButton("确认", (dialog, which) -> loginOut()).show();
                break;
            case R.id.sys_yinsi_tv:
                Intent intent2 = new Intent(mContext, WebActivity.class);
                intent2.putExtra("webType", 3);
                startActivity(intent2);

                break;

            case R.id.sys_delete_tv:
                new AlertDialog.Builder(mContext).setTitle("确认注销该账户？")
                        .setNegativeButton("我再想想", null)
                        .setPositiveButton("确认注销", (dialog, which) -> {
                            httpDelete();
                        }).show();
                break;
        }
    }

    //zhuxiao
    private void httpDelete() {
        HttpParams params = new HttpParams();
        params.put("userid", SPHelper.getString(MeConstant.UID, ""));
        HpGo.newInstance().HttpGo(this, MyUrl.DELETE_ACCONT, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                MyUtil.mytoast0(mContext,"注销成功");

                loginOut();

            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, /*code + "," +*/ msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }

    private void loginOut() {
        SPHelper.clear();
        setResult(0x88);
        finish();
    }
}
